
var CcaAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));

	
		this.controller.setupWidget("calciumField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
			

	this.controller.setupWidget("albField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
	
		this.controller.setupWidget("nalbField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: 40});
	

},


unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("calciumUnit").update("<span class=\"si\">(mg/dL)</span>");
$("albUnit").update("<span class=\"si\">(g/dL)</span>");
$("nalbUnit").update("<span class=\"si\">(g/dL)</span>");
}

if (unitchoice){
$("calciumUnit").update("<span class=\"si\">(mmol/L)</span>");
$("albUnit").update("<span class=\"si\">(g/L)</span>");
$("nalbUnit").update("<span class=\"si\">(g/L)</span>");
}
},

calculate: function() {

var result = ccacalc(this.togglemodel.togglestate,parseFloat($("calciumField").mojo.getValue()),parseFloat($("albField").mojo.getValue()),parseFloat($("nalbField").mojo.getValue()));

if (isNaN(result.cca)){
return errormsg;
}
else {
return "The corrected calcium is "+ result.cca +result.units;
}
}
});



